/*
 * Copyright (C) 2004, Velocityme Partnership
 * ProjectValueActionForm.java
 *
 * Created on 06 October 2004, 08:12
 */

package com.velocityme.www.actionforms.nodeactionforms;

import com.velocityme.entity.Project;
import com.velocityme.session.ContactableLocal;
import com.velocityme.session.KeyLocal;
import com.velocityme.session.PersonLocal;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author  Robert
 */
public class ProjectActionForm extends ActivityActionForm {
    
    private long m_sponsorId;
    private long m_primaryContactId;

    public void extractProject(KeyLocal key, Project project) {
        extractActivity(key, project);
        project.setSponsor(lookupContactableBean().findContactable(key, m_sponsorId));
        project.setPrimaryContact(lookupPersonBean().findPerson(key, m_primaryContactId));
    }

    public long getSponsorId() {
        return m_sponsorId;
    }
    
    public void setSponsorId(long sponsorId) {
        m_sponsorId = sponsorId;
    }
    
    public long getPrimaryContactId() {
        return m_primaryContactId;
    }
    
    public void setPrimaryContactId(long primaryContactId) {
        m_primaryContactId = primaryContactId;
    }

    private ContactableLocal lookupContactableBean() {
        try {
            Context c = new InitialContext();
            return (ContactableLocal) c.lookup("java:comp/env/ContactableBean");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    private PersonLocal lookupPersonBean() {
        try {
            Context c = new InitialContext();
            return (PersonLocal) c.lookup("java:comp/env/PersonBean");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }
    
}
